package com.ling.service.admin;

import com.ling.bean.Admin;
import com.ling.bean.AdminExample;
import com.ling.dao.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminService {

    private final AdminMapper adminMapper;

    @Autowired
    public AdminService(AdminMapper adminMapper) {
        this.adminMapper = adminMapper;
    }

    //判断管理员账号
    public boolean checkAdmin(Admin admin) {
        AdminExample adminExample = new AdminExample();
        adminExample.createCriteria().andUsernameEqualTo(admin.getUsername()).andPasswordEqualTo(admin.getPassword());
        long count = adminMapper.countByExample(adminExample);
        return count>0;
    }


    //获取管理员信息
    public Admin getAdmin(Admin admin) {
        AdminExample adminExample = new AdminExample();
        adminExample.createCriteria().andUsernameEqualTo(admin.getUsername()).andPasswordEqualTo(admin.getPassword());
        return adminMapper.selectByExample(adminExample).get(0);
    }
}
